package com.sheepone.util.string;

/**
 * @author Miss.杨
 * @description
 * @since 2024/2/21 - 10:16
 */
public class StringUtil {
    private StringUtil() {
    }

    public static final String EMPTY_STRING = "";

    public static boolean hasLength(CharSequence str) {
        return str != null && !str.isEmpty();
    }

    public static boolean hasText(CharSequence str) {
        if (str == null) {
            return false;
        } else {
            int strLen = str.length();
            if (strLen == 0) {
                return false;
            } else {
                for (int i = 0; i < strLen; ++i) {
                    if (!Character.isWhitespace(str.charAt(i))) {
                        return true;
                    }
                }

                return false;
            }
        }
    }

    public static boolean hasText(String str) {
        return str != null && !str.isBlank();
    }

    public static String underscoreToCamelCase(String input) {
        if (input == null || input.isEmpty()) {
            return input;
        }

        StringBuilder result = new StringBuilder(input.length());
        boolean capitalizeNext = false;

        for (int i = 0; i < input.length(); i++) {
            char ch = input.charAt(i);

            if (ch == '_') {
                capitalizeNext = true;
            } else if (capitalizeNext) {
                result.append(Character.toUpperCase(ch));
                capitalizeNext = false;
            } else {
                result.append(ch);
            }
        }

        return result.toString();
    }

}
